from django.contrib.admin.templatetags.admin_list import result_headers as _result_headers
from django.template import Library, TemplateSyntaxError, Node, Template, Context
#from django import forms
from django.db import models
from nokia.netact.models import *
from django import forms
from django.contrib.contenttypes.models import ContentType
from nokia.decorators import * 



register = Library()
BASE_DIR = 'reporting/tags/'

@register.inclusion_tag(BASE_DIR + 'example_table.html')
def example_table(report, number=5):
	"""Produce an example table to show what the report will output"""
	reporter = report.get_report()
	#columns is for the table, each will have the class of the FieldReport's type
	columns = [f.type.lower() for f in reporter.fields]
	headers = [{'title': f.title,'desc':f.function.__doc__} for f in reporter.fields]
	body = list(reporter(report.model.objects.all()[:number]))[1:] #Get rid of the header row
	return { 'cols': columns,
			 'headers': headers,
			 'body': body
		   }


class ROManipulator(forms.Manipulator):
    def __init__(self, *types):
        """Create an OSSTicketItem, given a ticket"""
        if not len(types):
            self.choices = ((1,'test'),(2,'test again'))
        else:
            self.choices = get_ro_choices(*types)
        self.fields = (
            forms.SelectMultipleField(field_name='ne', size=10,\
                            choices=self.choices),
            )

@register.inclusion_tag(BASE_DIR + "ne_form.html")
def ne_form():
    types = RANObjectType.objects.filter(abbreviation__in=('RNC','WBTS'))
    manipulator = ROManipulator(*types)
    ne_form = forms.FormWrapper(manipulator)
    print ne_form.fields
    return {'ne_form': ne_form}

